
#ifndef _COMMON_SINGLETON_H_
#define _COMMON_SINGLETON_H_

#include <stddef.h>

namespace common
{

	/**
	* @brief 单键模板类
	*
	*/
	template<class T>
	class CSingleton
	{
	public:

		/**
		* @brief 获取单键实例
		*
		* @return 返回实例
		*/
		static T& GetInstance( )
		{
			if ( NULL == instance_ )
			{
				instance_ = new T;
			}
			return *instance_;
		}

		static void ReleaseInstance( )
		{
			if ( NULL != instance_ )
			{
				delete instance_;
				instance_ = NULL;
			}
		}

		CSingleton( ) { }
	private:
		CSingleton( T& t );
		T& operator=( const T& t ) ;

	private:
		static T* instance_;/**<静态实例  */
	};

	template<class T>
	T* CSingleton<T>::instance_ = NULL;

}

#endif
